package sg.edu.nus.iss.vmcs.customer;
import java.awt.Color;
import java.awt.Composite;
import java.awt.Dialog;
import java.awt.Dimension;
import java.awt.Frame;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.util.Observable;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.SwingConstants;

import sg.edu.nus.iss.vmcs.system.ChangeDispenseButtonListener;
import sg.edu.nus.iss.vmcs.system.MainController;
import sg.edu.nus.iss.vmcs.system.RestartButtonListener;
import sg.edu.nus.iss.vmcs.system.TerminateButtonListener;
import sg.edu.nus.iss.vmcs.system.TransactionController;
import sg.edu.nus.iss.vmcs.util.LabelledDisplay;
import sg.edu.nus.iss.vmcs.util.WarningDisplay;

/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class AwtCustomerPanel extends Dialog implements CustomerUI {

	private static final String TITLE = "VMCS-Customer Panel";
	private JLabel custTitle;
	private LabelledDisplay totalMoneyInsertedDisplay;
	private WarningDisplay InvalidCoinDisplay;
	private WarningDisplay noChngLbl;
	private LabelledDisplay collectCanLbl;
	private LabelledDisplay collectCoinsLbl;
	private JButton terminateAndReturnBtn;
	private JButton restartBtn;
	private JButton changeBtn;
	private TransactionController txnController;
	private CoinInputBox coinInputBox;
	private DrinksSelectionBox drinksSelectionBox;
	private MainController mcntrl;
	private CoinReceiver coinReceiver;
	private Frame fm;
	
	public AwtCustomerPanel(Frame fm, TransactionController txnController, MainController mcntrl) {
		super(fm, TITLE, false);
		this.fm = fm;
		this.txnController = txnController;
		this.mcntrl= mcntrl;
		coinReceiver = (CoinReceiver)txnController.getCoinReceiver();
		initGUI();
	}

	private void initGUI() {
		try {
			{
				GridBagLayout thisLayout = new GridBagLayout();
				thisLayout.rowWeights = new double[] {0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.0, 0.1, 0.0, 0.1};
				thisLayout.rowHeights = new int[] {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 35, 0};
				thisLayout.columnWeights = new double[] {0.1, 0.1, 0.1, 0.1, 0.1, 0.1};
				thisLayout.columnWidths = new int[] {1, 1, 1, 1, 1, 1};
				this.setLayout(thisLayout);
				//this.setSize(300, 600);
				this.setPreferredSize(new Dimension(650, 700));
				{
					custTitle = new JLabel();
					this.add(custTitle, new GridBagConstraints(0, 0, 6, 1, 0.0, 0.0, GridBagConstraints.SOUTH, GridBagConstraints.NONE, new Insets(30, 0, 0, 0), 0, 0));
					custTitle.setText("VIMTO Soft Drink Dispenser");
					custTitle.setFont(new java.awt.Font("Segoe UI",1,18));
				}
				{
					coinInputBox = new CoinInputBox(mcntrl,this,coinReceiver);
					coinInputBox.display();
					this.add(coinInputBox, new GridBagConstraints(0, 1, 6, 2, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(10, 10, 10, 10), 0, 0));
				}
				{
					InvalidCoinDisplay = new WarningDisplay("Invalid Coin", txnController.getCoinReceiver());
					this.add(InvalidCoinDisplay, new GridBagConstraints(0, 3, 6, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.VERTICAL, new Insets(10, 10, 10, 10), 0, 0));
				}
				{
					totalMoneyInsertedDisplay = new LabelledDisplay("Total Money Inserted",10, LabelledDisplay.FLOW, txnController.getCoinReceiver());
					totalMoneyInsertedDisplay.setEditable(false);
					totalMoneyInsertedDisplay.setActive(true);
					this.add(totalMoneyInsertedDisplay, new GridBagConstraints(0, 4, 6, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(10, 10, 10, 10), 0, 0));
				}
				{
					drinksSelectionBox = new DrinksSelectionBox(mcntrl);
					this.add(drinksSelectionBox, new GridBagConstraints(0, 6, 6, 5, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(10, 10, 10, 10), 0, 0));
				}
				{
					noChngLbl = new WarningDisplay("No Change Available");
					this.add(noChngLbl, new GridBagConstraints(1, 11, 4, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(10, 10, 10, 10), 0, 0));
				}
				{
					terminateAndReturnBtn = new JButton();
					this.add(terminateAndReturnBtn, new GridBagConstraints(0, 12, 2, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(10, 10, 10, 10), 0, 0));
					terminateAndReturnBtn.setText("Terminate");
					terminateAndReturnBtn.addActionListener(new TerminateButtonListener(mcntrl));
				}
				{
					restartBtn = new JButton();
					this.add(restartBtn, new GridBagConstraints(2, 12, 2, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(10, 10, 10, 10), 0, 0));
					restartBtn.setText("Restart!!");
					restartBtn.addActionListener(new RestartButtonListener(mcntrl));
				}
				{
					changeBtn = new JButton();
					this.add(changeBtn, new GridBagConstraints(4, 12, 2, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(10, 10, 10, 10), 0, 0));
					changeBtn.setText("Give Change");
					changeBtn.addActionListener(new ChangeDispenseButtonListener(mcntrl));
				}
				
				{
					collectCoinsLbl = new LabelledDisplay("Collect Coins Here",10,LabelledDisplay.FLOW, txnController.getCoinReceiver());
					collectCoinsLbl.setEditable(false);
					this.add(collectCoinsLbl, new GridBagConstraints(1, 13, 5, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(10, 10, 10, 10), 0, 0));
					
				}
				
				{
					collectCanLbl = new LabelledDisplay("Collect Can Here", 10, LabelledDisplay.FLOW);
					collectCanLbl.setEditable(false);
					this.add(collectCanLbl, new GridBagConstraints(1, 14, 6, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(10, 10, 10, 10), 0, 0));
				}
			}
			pack();
		} catch(Exception e) {
			e.printStackTrace();
		}
	}
	
	/*
	public CoinInputBox getCoinInputBox(){
		return this.coinInputBox;
	}
	*/
	
	public void display() {
		this.setVisible(true);
	}

	public void closeDown() {
	
	}
	
	public void allowDrinksSelection(boolean allowSelection) {
		boolean active = allowSelection;
		drinksSelectionBox.setDrinkSelectionBoxActive(active);
	}
	
	public void setInvalidLabel(boolean state)
	{
		InvalidCoinDisplay.setState(state);
	}
	
	/*
	public DrinksSelectionBox getDrinkSelectionBox()
	{
		return drinksSelectionBox;
	}
	*/
}
